package com.bite.friend.Controller;


import com.bite.friend.DTO.UserDTO;
import com.bite.friend.DTO.UserDetailDTO;
import com.bite.friend.DTO.UserHeadImageDTO;
import com.bite.friend.Service.UserService;
import com.bite.friend.VO.UserInfoVO;
import com.bite.friend.VO.UserVO;
import domain.R;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.annotations.MultiField;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/user")
/**
 * C端用户
 */
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 触发短信验证码
     * @return
     */
    @PostMapping("/sendCode")
    public R<Void> sendCode(@RequestBody UserDTO userDTO){
        return userService.send(userDTO);
    }


    /**
     * 登录
     * @param userDTO
     * @return
     */
    @PostMapping("/login")
    public R<String> login(@RequestBody UserDTO userDTO){
        return userService.login(userDTO);
    }


    /**
     * 退出
     * @param token
     * @return
     */
    @GetMapping("/logOut")
    public R<Void> logOut(@RequestHeader String token){
        return userService.logOut(token);
    }


    /**
     * 获取用户信息
     * @return
     */
    @GetMapping("/getUserInfo")
    public R<UserInfoVO> getUserInfo(){
        return userService.getUserInfo();
    }


    /**
     * 个人中心
     * @return
     */
    @GetMapping("/personal")
    public R<UserVO> personal(){
        return userService.personal();
    }

    /**
     * 编辑个人信息
     */
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody UserDetailDTO userDetailDTO){
        return userService.edit(userDetailDTO);
    }

    /**
     * 头像修改
     * @param field
     * @return
     */
    @PostMapping("/headImage")
    public R<String> handImage(@RequestParam("file") MultipartFile file){
        return userService.headshot(file);
    }

    /**
     * 将头像url存入数据库中
     * @param userHeadImageDTO
     * @return
     */
    @PostMapping("/updateHeadImage")
    public R<Void> updateHeadImage(@RequestBody UserHeadImageDTO userHeadImageDTO){
        return userService.updateHeadImage(userHeadImageDTO);
    }







}
